package com.zh.baselibrary.base;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.trello.rxlifecycle2.LifecycleTransformer;
import com.trello.rxlifecycle2.android.ActivityEvent;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

import butterknife.ButterKnife;

public abstract class BaseActivity<P extends BasePresenter>extends RxAppCompatActivity implements BaseView{
    protected P mPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(getLayoutId()!=0)
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        mPresenter = createPresenter();
        if (mPresenter != null) {
            mPresenter.attachModelView( this, this);
        }
        init();
    }
    protected abstract int getLayoutId();
    protected abstract void init();
    /**
     * 使用MVP模式时需要重写该方法
     */
    protected abstract  P createPresenter();
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDetach();
        }
    }
    @Override
    public <T> LifecycleTransformer<T> bindToLife() {
        return bindUntilEvent(ActivityEvent.STOP);
    }

    @Override
    public void onSuccess(Object object) {

    }

    @Override
    public void onHint(String hint) {
    }
}
